package com.party.admin.biz.system;

import com.party.core.model.crowdfund.Support;
import com.party.core.model.member.MemberAct;
import com.party.core.model.member.MemberGroup;
import com.party.core.model.member.PartnerMember;
import com.party.core.service.crowdfund.ISupportService;
import com.party.core.service.member.IMemberActService;
import com.party.core.service.member.IMemberGroupService;
import com.party.core.service.member.IPartnerMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 机构会员业务接口
 * Created by wei.li
 *
 * @date 2017/9/25 0025
 * @time 11:39
 */
@Service
public class PartnerMemberBizService {

    @Autowired
    private IMemberGroupService memberGroupService;

    @Autowired
    private IMemberActService memberActService;

    @Autowired
    private ISupportService supportService;

    @Autowired
    private IPartnerMemberService partnerMemberService;

    public void init() throws InterruptedException {
        List<MemberGroup> list = memberGroupService.getAllPartnerNoOpenStatus();
        PartnerMember partnerMember = new PartnerMember();
        for (MemberGroup partner : list){

            //报名会员
            List<MemberAct> applicantList = memberActService.applicantList(partner.getId());

            //众筹支持会员
            List<Support> favorerList = supportService.favorerList(partner.getId());
            partnerMember.setPartnerId(partner.getId());
            for (MemberAct memberAct : applicantList){
                partnerMember.setId(null);
                partnerMember.setMemberId(memberAct.getMemberId());
                partnerMemberService.insert(partnerMember.getPartnerId(), partnerMember.getMemberId(), memberAct.getCreateDate());
            }

            for (Support support : favorerList){
                partnerMember.setId(null);
                partnerMember.setMemberId(support.getFavorerId());
                partnerMember.setCreateDate(support.getCreateDate());
                partnerMemberService.insert(partnerMember.getPartnerId(), partnerMember.getMemberId(), support.getCreateDate());
            }
        }
    }
}
